package model

import business.Attackable
import business.Blockable
import business.Destroyable
import business.Sufferable
import org.itheima.kotlin.game.core.Painter


/**
 * created by lucus on 2019/4/29
 * e-mail: mcphilex1989@gmail.com
 * phone: 15652608401
 */
class Camp(override var x: Int, override var y: Int) : Blockable, Sufferable, Destroyable {

    override var blood: Int = 12
    override var width: Int = BaseConfig.GAME_UNIT * 2
    override var height: Int = BaseConfig.GAME_UNIT * 2

    override fun draw() {
        if (blood <= 3) { // 老鹰
            width = BaseConfig.GAME_UNIT
            height = BaseConfig.GAME_UNIT
            x = (BaseConfig.GAME_WINDOW_WIDTH - BaseConfig.GAME_UNIT) / 2
            y = BaseConfig.GAME_WINDOW_HEIGHT - BaseConfig.GAME_UNIT
            Painter.drawImage("img/symbol.gif", x, y)
        } else if (blood <= 6) {// 砖块
            Painter.drawImage("img/wall_small.gif", x, y)
            Painter.drawImage("img/wall_small.gif", x + 32, y)
            Painter.drawImage("img/wall_small.gif", x + 64, y)
            Painter.drawImage("img/wall_small.gif", x + 96, y)
            Painter.drawImage("img/wall_small.gif", x, y + 32)
            Painter.drawImage("img/wall_small.gif", x, y + 64)
            Painter.drawImage("img/wall_small.gif", x + 96, y + 32)
            Painter.drawImage("img/wall_small.gif", x + 96, y + 64)
            Painter.drawImage("img/symbol.gif", x + 32, y + 32)
        } else { // 铁块
            // 顶部铁块
            Painter.drawImage("img/steel_small.gif", x, y)
            Painter.drawImage("img/steel_small.gif", x + 32, y)
            Painter.drawImage("img/steel_small.gif", x + 64, y)
            Painter.drawImage("img/steel_small.gif", x + 96, y)

            // 左边铁块
            Painter.drawImage("img/steel_small.gif", x, y + 32)
            Painter.drawImage("img/steel_small.gif", x, y + 64)

            // 右边铁块
            Painter.drawImage("img/steel_small.gif", x + 96, y + 32)
            Painter.drawImage("img/steel_small.gif", x + 96, y + 64)

            // 总部
            Painter.drawImage("img/symbol.gif", x + 32, y + 32)

        }

    }

    override fun notifySuffer(attackable: Attackable): Array<IView>? {
        blood -= attackable.attackBlood
        if (blood == 3 || blood == 6) {
            return arrayOf(
                Blast(x - 16, y - 16),
                Blast(x - 16, y + 16),
                Blast(x - 16, y + 48),
                Blast(x + 16, y - 16),
                Blast(x + 46, y - 16),
                Blast(x + 80, y - 16),
                Blast(x + 80, y + 16),
                Blast(x + 80, y + 46)
            )
        }
        return null
    }

    override fun isDestroy(): Boolean {
        return blood < 0
    }

    override fun showDestroy(): Array<IView>? {
        return arrayOf(
            Blast(x - 32, y - 32),
            Blast(x, y - 32),
            Blast(x + 32, y - 32),
            Blast(x - 32, y),
            Blast(x, y),
            Blast(x + 32, y),
            Blast(x - 32, y + 32),
            Blast(x, y + 32),
            Blast(x + 32, y + 32)
        )
    }


}